<template>
	<view class="ReportPDF">
		<view class="name">
			<uni-list>
				<uni-list-item title="任务名称" showArrow clickable @click="selectRW" :right-text="TaskName">
					<template v-slot:footer>
						<view class="taskName">
							{{TaskName}}
						</view>
					</template>
				</uni-list-item>
			</uni-list>
		</view>
		<view v-if="data.length<=0" style="text-align: center;">
			暂无数据
		</view>
		<!-- <view class="" v-else>
			<view style="border:2px solid magenta" class="" v-for="(item,index) in data" :key="index">
				<u-row justify="space-between" customStyle="margin-bottom: 10px">
					<u-col span="3">
						<view class="title" style="border:1px solid green;">
							{{item.ReportName}}
						</view>
					</u-col>
					<u-col span="3">
						<view class="" style="border:3px solid blue">
							<text style="color:#6060FF;font-size:30rpx" @click="download(item.PdfUrl)">下载</text>
						</view>
					</u-col>
				</u-row>
				<u-row>
					<u-col span="3">
						<view class="demo-layout bg-purple-light">这里是时间</view>
					</u-col>
				</u-row>
			</view>
		</view> -->
		<uni-list v-else>
			<uni-list-item v-for="item in data" :key="item.Id" :title="item.ReportName"
				:note="item.CreateTime.substring(0,19)">
				<template v-slot:footer>
					<view class="footer">
						<view @click="download(item.PdfUrl)">下载</view>
					</view>
				</template>
			</uni-list-item>
		</uni-list>
		<listitemRW ref="listitemRW" :showAdd="false" :xmId="ProjectId" :xmName="ProjectName" @itemClick="RWSelect"
			@backXM="backXM">
		</listitemRW>
	</view>

</template>

<script>
	import listitemRW from '@/components/listitem/listitemRW.vue'
	export default {
		props: {
			pName: {
				require: false
			},

			pid: {
				require: false
			}
		},
		components: {
			listitemRW,
		},
		data() {
			return {
				data: [],
				total: 0,
				pagination: {
					PageIndex: 1,
					PageRows: 20,
					SortField: "Id",
					SortType: "desc",
				},
				ProjectId: '', // 项目
				ProjectName: '',
				TaskId: '',
				TaskName: '',

			}
		},
		mounted() {
			this.getDataList()
			this.ProjectId = this.pid
			this.ProjectName = this.pName
		},
		methods: { // 选择任务
			selectRW() {
				if (!this.ProjectId) return uni.showToast({
					icon: 'none',
					title: '请选择项目'
				})
				this.$refs.listitemRW.open()
			},
			RWSelect(row) {
				this.TaskId = row.Id
				this.TaskName = row.Name
				this.getDataList()
				console.log(row)
			},
			concatList() {
				if (this.data.length >= this.total) return
				this.pagination.PageIndex++
				this.$http('Base_ProjectWork/Base_Project/GetProjectReportList', {
					...this.pagination,
					Search: {
						ProjectId: this.pid,
						TaskId: this.TaskId,
					}

				}).then(res => {
					if (res.Success) {
						this.data = this.data.concat(res.Data)
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
			},
			// 获取
			getDataList() {
				this.pagination.PageIndex = 1
				this.$http('Base_ProjectWork/Base_Project/GetProjectReportList', {
					...this.pagination,
					Search: {
						ProjectId: this.pid,
						TaskId: this.TaskId,

					}
				}).then(res => {
					if (res.Success) {
						this.data = res.Data
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
			},
			// 下载
			download(url) {
				uni.showLoading({
					title: 'PDF下载中',
					mask: true,
				})
				uni.downloadFile({
					url,
					header: {
						'Access-Control-Allow-Origin': '*'
					},
					filePath: '/Download',
					success: (res) => {
						console.log(res);
						uni.openDocument({
							filePath: res.tempFilePath,
							success: function(res) {
								console.log('打开文档成功');
							},
							fail: function(res) {
								uni.showToast({
									title: JSON.stringify(res)
								})
							}
						})
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							title: 'PDF下载失败,请重新尝试'
						})
					},
					complete() {
						uni.hideLoading()
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	// .title {
	// 	// width: 30%;
	// 	display: -webkit-box;
	// 	-webkit-box-orient: vertical;
	// 	-webkit-line-clamp: 2;
	// 	text-overflow: ellipsis;
	// 	overflow: hidden;
	// }
	/deep/.name {
		.uni-list-item__content-title {
			white-space: nowrap !important;
		}
	}

	/deep/.uni-list-item__content-title {
		white-space: pre-wrap !important;
	}

	/deep/.uni-list-item__container {
		align-items: center;
		padding: 5px;
		padding-left: 15px;
		// height: 46px;

	}

	.ReportPDF {
		.footer {
			color: #6060ff;
			display: flex;
			align-items: center;

		}
	}

	.margin {
		margin: 0 2%;
	}

	.taskName {
		padding: 0 15rpx;
		font-size: 36rpx;
		color: #336dba;
		font-weight: 600;
		line-height: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 480rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
</style>